/* This file is part of BORG.
 * BORG is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *  
 * BORG is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *   
 * You should have received a copy of the GNU General Public License
 * along with BORG; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 * 
 * Copyright 2003 by Mike Berger
 */
package net.sf.borg.model;

import java.util.StringTokenizer;

import net.sf.borg.common.PrefName;
import net.sf.borg.common.Prefs;

public class ReminderTimes {

	static private int times_[] = null;
	static private int NUM = 20;
	
	static public int getNum()
	{
		return NUM;
	}
	
	static public int getTimes(int i)
	{
		if( times_ == null )
		{
			// get times array from prefs
			times_ = new int[NUM];
			String s = Prefs.getPref(PrefName.REMMINS);
			arrayFromString(s);
		}
		return times_[i];
	}
	
	static public void setTimes(int times[])
	{
		times_ = times;
		String s = arrayToString(times_);
		Prefs.putPref(PrefName.REMMINS, s);
	}
	
	static private String arrayToString( int a[])
	{
		StringBuffer sb = new StringBuffer();
		for( int i = 0; i < a.length; i++)
		{
			sb.append(Integer.toString(a[i]));
			if( sb.length() != 0)
				sb.append(',');
		}
		
		return sb.toString();
	}
	
	static private void arrayFromString( String s)
	{
		StringTokenizer t = new StringTokenizer(s,",");
		for( int i = 0; i < NUM; i++)
		{
			if( t.hasMoreTokens())
			{
				String tok = t.nextToken();
				times_[i] = Integer.parseInt(tok);
			}
			else
			{
				times_[i] = 0;
			}
		}
	}
}
